<?php 
set_time_limit(1000);
//$pid = '113.0827,28.18398';

if(isset($pram[1]))getContent($pram[0],$pram[1],$pram[2],$pram[3],$weiboLogin);

function getContent($ac,$do,$pid,$y,$weiboLogin){
$pro = new Product();
for($a = $y;$a < 25;$a++){

$webpage = $weiboLogin->showTestPage( 'http://'.$ac.'.weibo.com/'.$do.'/'.$pid.'/'.$a.'');
//$f = fopen('sina.txt',"w");
//fwrite($f,$webpage);
//fclose($f);

$webpage = DeleteHtml($webpage);
//echo $webpage;exit();
//preg_match_all('|<input type="hidden" value="(.*)"|isU',$webpage,$lt);
preg_match_all('|<dl class="feed_list W_linecolor" id="(.*?)<dd class="clear">|is',$webpage,$main);
//$lat = $lt[1][1];
//$lang = $lt[1][2];

for($n=0,$m=0;$n< count($main[1]);$n++){
	
	preg_match_all('|<li><img id="(.*)" src="(.*)" class="bigcursor"|is',$main[1][$n],$weiboimg);
	if(empty($weiboimg[2][0]))continue;
	
	preg_match_all('|<dt class="face"><a class="card_box" alt="(.*)" href="/u/(.*)"><img width="50" height="50" src="(.*)"></a></dt>|isU',$main[1][$n],$face_c);
	//var_dump($face_c);	
	$facepath = str_replace('/50/','/180/',$face_c[3][0]);
	$facefile = 'sina/avatar/'.$face_c[2][0].'.jpg';
	$weiboLogin->getImage($facepath,$facefile);
	preg_match('|<p class="wbcon">(.*?)</p>|is',$main[1][$n],$weibo);
	//$wc = strip_tags($weibo[1]);
	//echo $main[1][$n];
	$content = delSpace($main[1][$n]);
	preg_match('|class="card_content"alt="'.$face_c[1][0].'">(.*?)</a>|is',$content,$name);
	preg_match_all('|<aclass="showmapbox"action-data="(.*?)\|(.*?)\|\|http://|is',$content,$addr);
	$address = $addr[1][0];
	$lt = explode(',',$addr[2][0]);
	$lat = $lt[0];
	$lang = $lt[1];
	preg_match('|target="_blank"class="date">(.*?)</a>|is',$content,$wtime);
	$wtime = $wtime[1];
	//echo $content;
	//var_dump(count($main[1]));exit();
	
	$file = 'sina/sina'.time().rand(0,1000).rand(0,1000).'.jpg';
	$image = str_replace('thumbnail','large',$weiboimg[2][0]);
	$weiboLogin->getImage($image,$file);
	
	if(is_int(strpos($wtime,'今天'))){
		$year = date('Y-m-d',time());
		$temp = str_replace('今天','',$wtime);
		$temp.=':00';
		$time = $year.'-'.$temp;
	}else{
		$year = date("Y",time());
		$temp = str_replace('月','-',$wtime);
		$temp = str_replace('日',' ',$temp);
		$temp.=':00';
		$time = $year.'-'.$temp;  
	}       
	
	//var_dump(filesize($file));exit();
	//echo $image;
	
	if(file_exists($file) && filesize($file) > 5000){
		$d = array("image" => $file,
						 "lat" => $lat,
						 "avatar" => $facefile,
						 "address" => $address,
						 "content" => $weibo[1],
						 "lang" => $lang,
						 "pid" => $pid,
						 "imageurl" => $image,
						 "uid" => $face_c[1][0],
						 "name" => $name[1],
						 "create_time" => date("Y-m-d H:i:s",time()),
						 "time" => $time);
	var_dump($d);
	echo $pro->addSina($d);
	sleep(rand(2,4));
	}else{
		$m++;		
		echo "<script type='text/javascript'>alert('curl错误');</script>";
		unlink($file);
		if($m == 2)continue;
		sleep(rand(8,16));
		$n--;
		continue;
	}
}
sleep(rand(5,8));
}
}



function DeleteHtml($str) { 
	$str = trim($str); 
	//$str = strip_tags($str,""); 
	$str = str_replace("\t","",$str); 
	$str = str_replace("\r\n","",$str); 
	$str = str_replace("\r","",$str); 
	$str = str_replace("\n","",$str); 
	$str = str_replace(" "," ",$str); 
	return trim($str); 
}
function delSpace($str){
	$str = trim($str); 
	$str = str_replace(" ","",$str); 
	return trim($str); 
}
?>
